package com.asura.course;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import com.asura.student.Student;

public class CourseSession implements Comparable<CourseSession> {
	public static final String ROTER_REPORT_HEADER = "XX学生名册";
	public static final String ROTER_REPORT_FOOTER = "总计学生人数：";
	private static int count = 0;

	private String department;
	private String number;
	private int numberOfStudents = 0;
	private Date startDate;

	private CourseSession() {
	}

	private CourseSession(String department, String number) {
		this.department = department;
		this.number = number;
	}

	private CourseSession(String department, String number, Date startDate) {
		this.department = department;
		this.number = number;
		this.startDate = startDate;
		this.count += 1;
	}

	public static void resetCount() {
		count = 0;
	}

	public String getDepartment() {
		return department;
	}

	public String getNumber() {
		return number;
	}

	public int getNumberOfStudents() {
		// TODO 自动生成的方法存根
		return students.size();
	}

	public Date getStartDate() {
		return startDate;
	}

	public Date createDate(int year, int month, int date) {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month - 1);
		calendar.set(Calendar.DAY_OF_MONTH, date);
		return calendar.getTime();

	}

	public void enroll(Student student) {
		// this.numberOfStudents = numberOfStudents + 1;
		students.add(student);
	}

	public ArrayList<Student> getAllStudents() {
		return students;
	}

	private ArrayList<Student> students = new ArrayList<Student>();

	public Object getEndDate() {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(startDate);
		int numberOfDays = 16 * 7 - 3;
		calendar.add(Calendar.DAY_OF_YEAR, numberOfDays);
		return calendar.getTime();
	}

	public String getRosterReport() {
		StringBuilder buffer = new StringBuilder();
		buffer.append(ROTER_REPORT_HEADER + "\n");

		Student student = students.get(0);
		buffer.append(student.getName());
		buffer.append("\n");

		buffer.append(students.get(1).getName());
		buffer.append("\n");
		buffer.append(ROTER_REPORT_FOOTER + students.size() + "\n");
		return buffer.toString();
	}

	public static int getCount() {
		// TODO 自动生成的方法存根
		return count;
	}

	public static CourseSession create(String department, String number, Date startDate) {
		return new CourseSession(department, number, startDate);
	}

	@Override
	public int compareTo(CourseSession session) {
		int compare = this.getDepartment().compareTo(session.getDepartment());
		if (compare == 0) {
			compare = this.getNumber().compareTo(session.getNumber());
		}
		return compare;
	}

}
